package com.hxzy.vo;


/**
 * 数据统一响应
 * @param <T>
 */
public class ResultVO<T> {
    //响应编号
    private int code;
    //响应消息
    private String message;
    //携带的值
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    /**
     * 成功(新增，修改以及其它)
     * @return
     */
    public static  ResultVO success(String message){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(ResultEnum.SUCDESS.getCode());   //1
        vo.setMessage(ResultEnum.SUCDESS.getMessage());  //success
        vo.setData(message);
        return vo;
     }

    /**
     * 成功(传值)
     * @param data
     * @param <T>
     * @return
     */
     public static <T> ResultVO  success(T data){
         ResultVO  vo=new ResultVO();
         vo.setCode(ResultEnum.SUCDESS.getCode());   //1
         vo.setMessage(ResultEnum.SUCDESS.getMessage());  //success
         vo.setData(data);
         return vo;
     }


    /**
     * 失败，必须给原因
     * @param resultEnum
     * @return
     */
    public static  ResultVO failed( ResultEnum  resultEnum){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(resultEnum.getCode());
        vo.setMessage(resultEnum.getMessage());
        return vo;
    }

}
